<!--
 * @Description: 商家远程项目数据报表
 * @Author: liyujie
 * @Date: 2021/08/02
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/08/02
-->
<template>
    <section class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    查看详情<span class="company-name">({{ company_name }}）</span>
                </div>
            </div>
            <!-- /header -->
            <div class="statistics-view">
                <div
                    class="statistics-item"
                    v-for="(item,index) in statistics_data"
                    :key="index"
                >
                    <div
                        class="statistics-icon"
                        :style="{backgroundImage: `url(https://cdn.zsdx.cn/phaadmin/task-icon${index + 1}.png)`}"
                    />
                    <div class="statistics-info">
                        <div class="statistics-info__label">{{ item.title }}</div>
                        <div class="statistics-info__value">
                            {{ item.value }}
                            <span style="font-size: 12px">{{ item.unit }}</span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 筛选-->
            <div class="filter-view">
                <div class="filter-left">
                    <div class="filter-item">
                        <p class="filter-item__title">
                            项目名称
                        </p>
                        <el-select
                            v-model="filterData.keyword"
                            filterable
                            clearable
                            size="medium"
                            style="width: 260px"
                            placeholder="请选择项目名称"
                            @change="getTableData(1)"
                        >
                            <el-option
                                v-for="item in project_list"
                                :key="item.shop_project_no"
                                :label="item.project_title"
                                :value="item.project_title"
                            />
                        </el-select>
                    </div>
                    <div class="filter-item">
                        <el-button
                            type="primary"
                            size="small"
                            class="query-button"
                            @click="getTableData(1)"
                        >
                            查询
                        </el-button>
                        <el-button
                            type="text"
                            @click="handleReset()"
                        >
                            重置
                        </el-button>
                    </div>
                </div>
                <div class="filter-right"/>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    class="data-table"
                    :cell-style="{height: '60px'}"
                    v-loading="tableLoading"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="80"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        prop="project_title"
                        label="项目名称"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="task_count"
                        label="任务总数(个)"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="task_apply_user_count"
                        label="用户参与数(人)"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="task_complete_user_count"
                        label="用户完成数(人)"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="项目状态"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    class="status-dot"
                                    :class="['status-dot', scope.row.project_status === 1 ? 'success' : 'danger']"
                                />
                                <div>{{ scope.row.project_status | statusFilter }}</div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="task_pay_money"
                        label="商家支出奖金"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <span style="color: #FF8E39">{{ scope.row.task_pay_money ? `￥${scope.row.task_pay_money}` : '--' }}</span>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </section>
</template>

<script>
import { back } from '@/mixin/back';
import {deepClone} from "@/assets/js/utils";

export default {
    name: 'ShopProjectStatisticsDetail',
    mixins: [back],
    components: {},
    data() {
        return {
            company_name: '',
            filterData: {
                keyword: '',
                shop_no: ''
            },
            tableData: [],
            statistics_data: [
                {title: '任务数量', value: 0, unit: '个'},
                {title: '参与用户数  ', value: 0, unit: '人'},
                {title: '完成用户数', value: 0, unit: '人'},
                {title: '商家支出奖金', value: 0, unit: '元'},
            ],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            project_list: [],
            authResult: {}
        };
    },
    computed: {},
    filters: {
        statusFilter(val) {
            switch (val) {
                case 1:
                    return '已上架';
                case 0:
                    return '已下架';
                default:
                    return '--';
            }
        },
    },
    watch: {},
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '商家远程项目'}, {title: '商家项目数据', path: '/student/shop-project-statistics'}, {title: '查看详情'}]);
        this.authResult = this.$route.meta.authResult;
        this.filterData.shop_no = this.$route.query.shop_no;
        this.company_name = this.$route.query.company_name;
        this.getTableData();
        this.getProjectList();
    },

    methods: {

        /**
         * @description 获取下拉数据
         */
        getProjectList() {
            this.$post('/student/task_stuagent_shop_project%5Cget_list_for_select', {}, res => {
                if (res.code === 1) {
                    this.project_list = res.data;
                }
            });
        },

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/task_stuagent_for_shop%5Cget_shop_statistic_detail_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                    if(res.data.statistic) {
                        this.statistics_data[0].value = res.data.statistic.task_count;
                        this.statistics_data[1].value = res.data.statistic.task_apply_user_count;
                        this.statistics_data[2].value = res.data.statistic.task_complete_user_count;
                        this.statistics_data[3].value = res.data.statistic.task_pay_money;
                    }
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 重置筛选条件
         */
        handleReset() {
            this.filterData.keyword = '';
            this.getTableData(1);
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
            .company-name {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #2FBDB3;
                margin-left: 12px;
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 32px;
            margin-top: 24px;
            .filter-left {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .filter-right {
                display: flex;
            }

            .filter-item {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 24px;

                &__title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        .statistics-view {
            display: flex;
            align-items: center;
            margin-top: 24px;
            padding: 0 32px;
            .statistics-item {
                flex: 1;
                margin-right: 24px;
                height: 87px;
                border-radius: 12px;
                display: flex;
                padding: 15px 32px;
                &:nth-of-type(1) {
                    background: #E8F8FF;
                }
                &:nth-of-type(2) {
                    background: #F3F3FF;
                }
                &:nth-of-type(3) {
                    background: #FFF0EE;
                }
                &:last-of-type {
                    margin-right: 0;
                    background: #FFF9F5;
                }
                .statistics-icon {
                    width: 24px;
                    height: 24px;
                    background-size: cover;
                    background-position: center center;
                    margin-right: 12px;
                }
                .statistics-info {
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #333333;
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                    &__label {
                        font-size: 14px;
                        margin-bottom: 15px;
                    }
                    &__value {
                        font-size: 18px;
                    }
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 32px;
            flex: 1;
            height: 0;
            .project-logo {
                width: 40px;
                height: 40px;
                object-fit: cover;
            }
        }
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */
        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-dialog__body {
        padding: 32px 64px 32px 47px;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
    /deep/ .el-radio-button {
        &.is-active {
            .el-radio-button__inner {
                background: #E6F1FC;
                color: #20A0FF;
                border-color: #20A0FF;
            }
        }
        .el-radio-button__inner {
            padding: 10px 24px;
        }
    }
    /deep/ .el-table {
        th {
            background: #f2f2f2!important;
            font-size: 14px!important;
            font-family: PingFangSC-Medium, PingFang SC!important;
            font-weight: 500!important;
            color: #333333!important;
            height: 44px!important;
        }
    }
}
</style>
